<template>
	<div id="home">
		<el-container>
			<el-aside width="200px">
				<div id="tree">
					<el-tree :data="data" :props="defaultProps" accordion @node-click="handleNodeClick">
					</el-tree>
				</div>
			</el-aside>
			<el-main class="el-main-home">
				<router-view :key="$route.fullPath"></router-view>
			</el-main>
		</el-container>
	</div>
</template>

<script>
	export default {
		name: 'tree',
		mounted() {
			this.$axios.get("/getMenuAll?uid=" + sessionStorage.getItem("userId")).then(res => {
				var menu = res.data;
				this.data=menu;
			})
		},
		watch: {
			'$route': 'getPath'
		},
		data() {
			return {
				data: [],
				defaultProps: {
					children: 'children',
					label: 'jname'
				}
			}
		},
		methods: {
			handleNodeClick(data) {
				this.jump(data);
			},
			getPath() {
				if(sessionStorage.getItem("userId")!=null)return;
				this.$router.push("/login");
			},
			//功能跳转
			jump(data) {
				if(data.jwebsite=='')return;//若路径为则直接结束方法
				this.$router.push("/home/"+data.jwebsite+"?jno="+data.jno);//跳转
			}
		}
	}
</script>

<style scoped>
	.el-main-home {
		margin-left: 5px;
	}

	.el-tree {
		height: 700px;
		border: #A8A8A8 1px solid;
	}

	.el-main {
		border: #A8A8A8 1px solid;
	}
	
</style>
